<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.PrintArea.js"></script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
    <div data-theme="a" data-role="header">        
        <a data-role="button" href="javascript:goback();" class="ui-btn-left">
            返回
        </a>
        <h3>
            扫描出库
        </h3>
    </div>
    <div data-role="content">
        <div class="ui-grid-a">
            <div class="ui-block-a" style="width:120px">
				仓库号：
            </div>
            <div class="ui-block-b">
               <?php echo $this->billall->user->storeno;?>&nbsp;&nbsp;(呢称:<?php echo $this->billall->user->nikename;?>&nbsp;&nbsp;国家:<?php echo $this->billall->UserCity->name;?>)
            </div>			
        </div>

		<div class="ui-grid-a">
			<div class="ui-block-a" style="width:120px">
				悠奇运单编号：
			</div>
			<div class="ui-block-b">
				<?php echo $this->billall->billNo;?>
			</div>
		</div>

		<div class="ui-grid-a">
			<div class="ui-block-a" style="width:120px">
				所在库位:
			</div>
			<div class="ui-block-b">
				<?php echo $this->billall->locationName;?>
			</div>
		</div>

        <div data-role="fieldcontain">
            <input id="brcode" name="brcode" placeholder="请输入包裹条形码" type="text">
        </div>
        <div id="res"></div>
        <div class="ui-grid-a">
            
           <?php
                if($this->storedetail != ''){
                foreach ($this->storedetail as $Item) {
          ?>
            
            <div class="ui-block-a" style="width:120px;height:110px;" id="div<?php echo $Item->barcode;?>">
                <img src="<?php echo $this->cdn;?><?php echo $Item->image;?>"/>
            </div>
            <div class="ui-block-b" id="divi<?php echo $Item->barcode;?>" style="height:100px;<?php if($Item->interior == Application_Model_StoreItem::Interior_PickIng){ echo "background-color:#B9F789"; }?>">
                <span>
                    <?php echo $Item->productName;?>
                </span><br/>
                <span>
                    【<?php echo $Item->barcode;?>】
                </span><br/>
                <span>
                    库位：<?php echo $Item->locationNo?$Item->locationNo:"暂无"; ?>
                </span><br/>
                <span>
                    状态：<?php echo $Item->InteriorName?$Item->InteriorName:"无状态";?>
                </span><br/>
            </div>
            <?php }}?>
                                    
        </div>
        <a data-role="button" target="_blank" data-direction="reverse" data-transition="none"
        href="javascript:pickerror();" id="pickerror" data-icon="refresh" data-iconpos="bottom">
            拣货异常
        </a>
    </div>
</div>

<script type="text/javascript">
 function showfocus(){
    $("#brcode").val("");
    $("#brcode").focus();
 }
 $("#brcode").focus();
$(document).ready(function(){ 
 $('#brcode').focus().keyup(function(e){
      if(e.keyCode === 13){
         var brcode = $("#brcode").val();
            $.ajax({    
                type: 'POST',
                url: '/admini/managewaybill/packstore/id/<?php echo $this->billall->id;?>/storeno/'+brcode,
                success: function(data) {
                    if(data.type === 1){
                        showmp3(brcode);
                        setTimeout("showfocus()",1000);
                        $('#res').html("<font size='5' color='green'>扫描OK</font>");
                    }else if(data.type === 100){
                        showmp3(brcode);
                        setTimeout("showfocus()",1000); 
                        setTimeout("showpicking()",1000); 
                    }else if(data.type === 2){
                        $('#res').html("<font size='5' color='red'>扫描出错---该包裹对应的用户是"+data.nikename+"("+data.storeno+")<br/>对应的运单Id="+data.wayid+"--状态为"+data.interior+"</font>"); 
                        scanerr();                            
                    }else if(data.type === 0){
                        $('#res').html("<font size='5' color='red'>该运单没有对应的包裹</font>"); 
                        scanerr();
                    }else if(data.type === 3){
                        $('#res').html("<font size='5' color='red'>无此包裹信息</font>"); 
                        scanerr();
                    }else if(data.type === 4){                       
                        $('#res').html("<font size='5' color='red'>无此包裹没有对应的运单号</font>");
                        scanerr();
                    }
                }
            });
     }
 }).blur(function(){
     $('#brcode').focus();
 });
 });
     
 function showmp3(brcode){
    $("#divi"+brcode).css("background","#B9F789");
    var audio = document.createElement('audio');
    audio.src = '/images/storage/success.mp3?rnd'+Math.random();//这里放音乐的地址
    audio.autoplay = 'autoplay';
    document.body.appendChild(audio);
}

function scanerr(){
    var audio = document.createElement('audio');
    audio.src = '/images/storage/xuxushishi.mp3?rnd'+Math.random();
    audio.autoplay = 'autoplay';
    document.body.appendChild(audio);
    setTimeout("showfocus()",1000);
}

function showpicking(){
    $.ajax({    
        type: 'POST',
        url: '/admini/managewaybill/affirmpick/id/<?php echo $this->billall->id;?>',
        success: function(data) {
            if(data === 1){
                alert("拣货完成！");
                location.href='/admini/managewaybill/billaccep/id/<?php echo $this->billall->id;?>';
            }else{
                alert("前台状态为已受理并且后台状态为（待拣货或者拣货异常）才能完成拣货");
            }
        }
    });
}

function pickerror(){
    if(confirm("您确定该运单拣货异常吗？","提示信息")){ 
        $.ajax({    
           type: 'POST',
           url: '/admini/managewaybill/affirmpickerror/id/<?php echo $this->billall->id;?>',
           success: function(data) {
               if(data === 1){
                   alert("标注拣货异常！");
               }else{
                   alert("前台状态为已受理并且后台状态为（待拣货或者拣货异常）才能标注拣货异常！");
               }
               location.href='/admini/managewaybill/tabletforpicking/status/1';
           }
       });
    }
}

function goback(){
    location.href='/admini/managewaybill/tabletforpicking/status/1';
}
</script>
</body>
</html>